import 'package:cached_network_image/cached_network_image.dart';
import 'package:calendar_date_picker2/calendar_date_picker2.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:travel/model/hotel.dart';
import 'package:travel/routes/index.dart';
import 'package:travel/ui/draw_under_line.dart';
import 'package:travel/utils/colors.dart';
import 'package:travel/utils/radian.dart';
import 'package:travel/utils/styles.dart';
import 'package:travel/utils/tools.dart';
import 'package:travel/screen/flutter_screenutil.dart';

class HotelController extends GetxController {
  RxDouble opacity = 0.0.obs;

  late TextEditingController textEditingController;

  late TextEditingController editingController;

  late ScrollController scrollController;

  RxInt tabIndex = 0.obs;

  RxList<HotelTypeModel> types = RxList([]);

  RxInt typeIndex = 0.obs;

  RxList<HotelModel> pageList = RxList([]);

  RxBool isLoading = false.obs;

  RxBool hasNext = true.obs;

  RxInt total = 35.obs;

  @override
  void onInit() {
    scrollController = ScrollController()
      ..addListener(() {
        double value =
            (scrollController.offset / 50.0).toDouble().clamp(0.0, 1.0);
        opacity.value = value;
        if (isLoading.isFalse &&
            scrollController.position.pixels >=
                scrollController.position.maxScrollExtent) {
          isLoading.value = true;
          loadMoreData();
        }
      });
    textEditingController = ToolsUtils.editingController('');
    editingController = ToolsUtils.editingController('');
    types.add(HotelTypeModel(name: '热门推荐', icon: 'u1372.svg'));
    types.add(HotelTypeModel(name: '本地热卖', icon: 'u1374.svg'));
    types.add(HotelTypeModel(name: '优选新店', icon: 'u1373.svg'));
    types.add(HotelTypeModel(name: '网红酒店', icon: 'u1375.svg'));
    types.add(HotelTypeModel(name: '滨海度假', icon: 'u1376.svg'));
    initData();
    super.onInit();
  }

  @override
  void onClose() {
    scrollController.dispose();
    editingController.dispose();
    textEditingController.dispose();
    super.onClose();
  }

  void initData() {
    pageList.add(HotelModel(
        name: '锦江之星风尚酒店(北海三里屯店)',
        address: '北海市海城区东直门外南二里庄29号1幢',
        price: 579,
        area: '海城区',
        imgUrl:
            'https://img2.baidu.com/it/u=546949935,3574777670&fm=253&fmt=auto&app=138&f=JPEG?w=638&h=500'));
    pageList.add(HotelModel(
        name: '北海万达文华酒店',
        address: '北海市银海区东直门外南二里庄29号1幢',
        price: 399,
        area: '银海区',
        imgUrl:
            'https://img1.baidu.com/it/u=2046807301,2551492904&fm=253&fmt=auto&app=138&f=JPEG?w=888&h=500'));
    pageList.add(HotelModel(
        name: '北海广渠门漫心酒店',
        address: '北海市合浦县东直门外南二里庄29号1幢',
        price: 478,
        area: '合浦县',
        imgUrl:
            'https://img1.baidu.com/it/u=1512264951,2503995626&fm=253&fmt=auto&app=120&f=JPEG?w=1200&h=800'));
    pageList.add(HotelModel(
        name: '锦江之星风尚酒店(北海三里屯店)',
        address: '北海市海城区东直门外南二里庄29号1幢',
        price: 389,
        area: '海城区',
        imgUrl:
            'https://img2.baidu.com/it/u=3206337597,3928032791&fm=253&fmt=auto&app=138&f=JPEG?w=750&h=500'));
    pageList.add(HotelModel(
        name: '北海望京希尔顿欢朋酒店',
        address: '北海市海城区东直门外南二里庄29号1幢',
        price: 189,
        area: '海城区',
        imgUrl:
            'https://img2.baidu.com/it/u=874687570,4272745671&fm=253&fmt=auto&app=138&f=JPEG?w=750&h=500'));
    pageList.add(HotelModel(
        name: '全季酒店(北海天坛店)',
        address: '北海市海城区东直门外南二里庄29号1幢',
        price: 489,
        area: '海城区',
        imgUrl:
            'https://img2.baidu.com/it/u=1915459,4007195949&fm=253&fmt=auto&app=138&f=JPEG?w=750&h=500'));
  }

  Future<void> loadMoreData() {
    return Future.delayed(const Duration(seconds: 1), () {
      if (total.value > pageList.length) {
        hasNext.value = true;
        isLoading.value = false;
        initData();
        return;
      }
      hasNext.value = false;
      isLoading.value = false;
    });
  }
}

class HotelView extends GetView<HotelController> {
  const HotelView({super.key});

  @override
  Widget build(BuildContext context) {
    return Obx(() => Container(
          height: Get.height,
          width: Get.width,
          decoration: const BoxDecoration(color: Colors.white),
          child: buildStack(context),
        ));
  }

  Widget buildStack(BuildContext context) {
    return Stack(
      children: [
        Image.network(
          'https://cdn7.axureshop.com/demo2024/2251242/images/酒店预订/专题图_u1346.png',
          width: Get.width,
          height: 300.h,
          fit: BoxFit.fill,
        ),
        SizedBox(
          width: Get.width,
          height: Get.height,
          child: Scaffold(
            backgroundColor: Colors.transparent,
            body: CustomScrollView(
              controller: controller.scrollController,
              slivers: [
                SliverAppBar(
                  backgroundColor:
                      ColorsUtils.rgba(255, 255, 255, controller.opacity.value),
                  elevation: 0,
                  automaticallyImplyLeading: true,
                  leading: InkWell(
                    onTap: () {
                      Get.back();
                    },
                    child: Icon(
                      Icons.arrow_back_ios,
                      color: ColorsUtils.parseColorFromHexString(
                          ColorsUtils.color3333),
                      size: 20.w,
                    ),
                  ),
                  leadingWidth: 40.w,
                  pinned: true,
                  title: Opacity(
                    opacity: controller.opacity.value,
                    child: Container(
                      height: 38.h,
                      padding: EdgeInsets.symmetric(horizontal: 10.w),
                      decoration: BoxDecoration(
                          borderRadius: BorderRadius.circular(20.w),
                          border: Border.all(
                              color: ColorsUtils.parseColorFromHexString(
                                  ColorsUtils.color3478))),
                      child: Row(
                        children: [
                          Column(
                            children: [
                              Container(
                                padding: EdgeInsets.only(top: 4.h),
                                alignment: Alignment.centerLeft,
                                child: Text.rich(TextSpan(
                                    text: '住 ',
                                    style: StylesUtils.customTextStyle(
                                        fontSize: 12.sp,
                                        color: ColorsUtils.color9999),
                                    children: [
                                      TextSpan(
                                          text: '11-25',
                                          style: StylesUtils.customTextStyle(
                                              fontSize: 12.sp,
                                              color: ColorsUtils.color3478))
                                    ])),
                              ),
                              Container(
                                padding: EdgeInsets.only(top: 3.h),
                                alignment: Alignment.centerLeft,
                                child: Text.rich(TextSpan(
                                    text: '离 ',
                                    style: StylesUtils.customTextStyle(
                                        fontSize: 12.sp,
                                        color: ColorsUtils.color9999),
                                    children: [
                                      TextSpan(
                                          text: '11-28',
                                          style: StylesUtils.customTextStyle(
                                              fontSize: 12.sp,
                                              color: ColorsUtils.color3478))
                                    ])),
                              )
                            ],
                          ),
                          Container(
                            padding: EdgeInsets.symmetric(horizontal: 5.w),
                            alignment: Alignment.centerLeft,
                            child: Text(
                              '北海',
                              style: StylesUtils.customTextStyle(
                                  fontSize: 13.sp,
                                  color: ColorsUtils.color3478),
                            ),
                          ),
                          Container(
                            alignment: Alignment.center,
                            child: ToolsUtils.assetImageSvg('u1366.svg',
                                width: 2.w, height: 15.h),
                          ),
                          Expanded(
                              child: Container(
                            padding: EdgeInsets.only(left: 5.w),
                            child: TextField(
                              controller: controller.textEditingController,
                              cursorWidth: 2.0,
                              cursorRadius: const Radius.circular(2),
                              cursorColor: ColorsUtils.parseColorFromHexString(
                                  ColorsUtils.color3333),
                              style: StylesUtils.customTextStyle(
                                  fontSize: 13.sp,
                                  color: ColorsUtils.color3333),
                              decoration: InputDecoration(
                                prefixIcon:
                                    Icon(Icons.search_sharp, size: 25.sp),
                                prefixIconColor: Colors.black54,
                                prefixIconConstraints:
                                    BoxConstraints.expand(width: 35.w),
                                border: InputBorder.none,
                                focusedBorder: InputBorder.none,
                                hintText: '酒店地名',
                                contentPadding:
                                    EdgeInsets.symmetric(vertical: 12.h),
                                isCollapsed: true,
                                isDense: true,
                                hintStyle: StylesUtils.customTextStyle(
                                    color: ColorsUtils.color3333,
                                    fontSize: 13.sp),
                              ),
                              readOnly: true,
                              onTap: () {
                                Get.toNamed(RoutePath.hotelSearch);
                              },
                            ),
                          ))
                        ],
                      ),
                    ),
                  ),
                  actions: [
                    TextButton(
                        onPressed: () {
                          Get.toNamed(RoutePath.hotelOrderList);
                        },
                        child: Text.rich(TextSpan(children: [
                          WidgetSpan(
                              child: ToolsUtils.assetImageSvg('u1355.svg',
                                  width: 14.w, height: 16.h),
                              alignment: PlaceholderAlignment.middle),
                          TextSpan(
                              text: ' 订单',
                              style: StylesUtils.customTextStyle(
                                  fontSize: 15.sp,
                                  color: ColorsUtils.color0000))
                        ])))
                  ],
                ),
                SliverToBoxAdapter(
                  child: Container(
                    padding: EdgeInsets.only(
                        left: 15.w, right: 15.w, top: 25.h, bottom: 15.h),
                    alignment: Alignment.centerRight,
                    child: Container(
                        alignment: Alignment.center,
                        constraints:
                            BoxConstraints.expand(width: 55.w, height: 20.h),
                        decoration: BoxDecoration(
                            borderRadius: BorderRadius.circular(10.h),
                            gradient: LinearGradient(
                                colors: [
                                  ColorsUtils.rgba(52, 120, 246, 1),
                                  ColorsUtils.rgba(2, 167, 240, 1)
                                ],
                                stops: const [
                                  0,
                                  0.99
                                ],
                                transform: GradientRotation(
                                    RadianUtils.angleToRadian(90)))),
                        child: InkWell(
                          onTap: () {
                            Get.toNamed(RoutePath.hotelActivity);
                          },
                          child: Center(
                              child: Text.rich(TextSpan(children: [
                            TextSpan(
                                text: '详情 ',
                                style: StylesUtils.customTextStyle(
                                    fontSize: 12.sp)),
                            WidgetSpan(
                                child: Icon(
                                  Icons.arrow_forward_ios,
                                  color: Colors.white,
                                  size: 10.sp,
                                ),
                                alignment: PlaceholderAlignment.middle)
                          ]))),
                        )),
                  ),
                ),
                SliverPadding(
                  padding: EdgeInsets.symmetric(horizontal: 15.w),
                  sliver: SliverToBoxAdapter(
                    child: Container(
                      decoration: BoxDecoration(
                          color: Colors.white,
                          borderRadius: BorderRadius.only(
                              topRight: Radius.circular(10.w),
                              topLeft: Radius.circular(10.w))),
                      child: Column(
                        children: [
                          Container(
                            height: 50.h,
                            alignment: Alignment.center,
                            decoration: BoxDecoration(
                                color: ColorsUtils.rgba(224, 241, 254),
                                borderRadius: BorderRadius.only(
                                    topRight: Radius.circular(10.w),
                                    topLeft: Radius.circular(10.w))),
                            child: CupertinoSegmentedControl<int>(
                              onValueChanged: (int? value) {
                                controller.tabIndex.value = value!;
                              },
                              //选中的背景颜色
                              selectedColor: Colors.blue,
                              //未选中的背景颜色
                              unselectedColor: Colors.white,
                              //边框颜色
                              borderColor: Colors.blue,
                              //按下的颜色
                              pressedColor: Colors.blue.withOpacity(0.4),
                              children: {
                                0: Container(
                                  width: 130.w,
                                  height: 30.h,
                                  alignment: Alignment.center,
                                  decoration: BoxDecoration(
                                      color: activeBackgroundColor(0)),
                                  child: Text('酒店', style: activeTextStyle(0)),
                                ),
                                1: Container(
                                  width: 130.w,
                                  height: 30.h,
                                  alignment: Alignment.center,
                                  decoration: BoxDecoration(
                                      color: activeBackgroundColor(1)),
                                  child: Text('月租房', style: activeTextStyle(1)),
                                ),
                                2: Container(
                                  width: 130.w,
                                  height: 30.h,
                                  alignment: Alignment.center,
                                  decoration: BoxDecoration(
                                      color: activeBackgroundColor(2)),
                                  child: Text('民宿', style: activeTextStyle(2)),
                                ),
                              },
                            ),
                          ),
                          Container(
                            height: 300.h,
                            padding: EdgeInsets.only(
                                left: 15.w, right: 15.w, top: 15.h),
                            child: Column(
                              children: [
                                Row(
                                  children: [
                                    Wrap(
                                      spacing: 40.w,
                                      alignment: WrapAlignment.start,
                                      runAlignment: WrapAlignment.start,
                                      crossAxisAlignment:
                                          WrapCrossAlignment.start,
                                      children: [
                                        Text(
                                          '城市',
                                          style: StylesUtils.customTextStyle(
                                              fontSize: 12.sp,
                                              color: ColorsUtils.color9999),
                                        ),
                                        Text(
                                          '位置',
                                          style: StylesUtils.customTextStyle(
                                              fontSize: 12.sp,
                                              color: ColorsUtils.color9999),
                                        )
                                      ],
                                    ),
                                  ],
                                ),
                                DrawUnderLine(
                                  color: ColorsUtils.parseColorFromHexString(
                                      ColorsUtils.colorF5f5),
                                  child: Container(
                                    padding: EdgeInsets.only(
                                        top: 10.h, bottom: 15.h),
                                    alignment: Alignment.centerLeft,
                                    child: Row(
                                      children: [
                                        InkWell(
                                            onTap: () {
                                              Get.toNamed(RoutePath.city);
                                            },
                                            child:
                                                Text.rich(TextSpan(children: [
                                              TextSpan(
                                                  text: '北海 ',
                                                  style: StylesUtils
                                                      .customTextStyle(
                                                          fontSize: 18.sp,
                                                          fontWeight:
                                                              FontWeight.w700,
                                                          color: ColorsUtils
                                                              .color3333)),
                                              WidgetSpan(
                                                  child:
                                                      ToolsUtils.assetImageSvg(
                                                          'u1405.svg',
                                                          width: 10.w,
                                                          height: 6.h),
                                                  alignment:
                                                      PlaceholderAlignment
                                                          .middle)
                                            ]))),
                                        Expanded(
                                            child: Container(
                                          padding: EdgeInsets.only(left: 15.w),
                                          alignment: Alignment.centerLeft,
                                          child: Text(
                                            '中山历史文化公园',
                                            style: StylesUtils.customTextStyle(
                                                fontSize: 18.sp,
                                                color: ColorsUtils.color3333,
                                                fontWeight: FontWeight.w700),
                                          ),
                                        )),
                                        Center(
                                          child: ToolsUtils.assetImageSvg(
                                              'u1393.svg',
                                              width: 18.w,
                                              height: 18.h),
                                        )
                                      ],
                                    ),
                                  ),
                                ),
                                DrawUnderLine(
                                    color: ColorsUtils.parseColorFromHexString(
                                        ColorsUtils.colorF5f5),
                                    child: Container(
                                      padding: EdgeInsets.only(bottom: 15.h),
                                      alignment: Alignment.centerLeft,
                                      child: Row(
                                        children: [
                                          Expanded(
                                              child: Column(
                                            children: [
                                              Container(
                                                alignment: Alignment.centerLeft,
                                                child: Text(
                                                  '今天入住',
                                                  style: StylesUtils
                                                      .customTextStyle(
                                                          fontSize: 12.sp,
                                                          color: ColorsUtils
                                                              .color9999),
                                                ),
                                              ),
                                              Container(
                                                alignment: Alignment.centerLeft,
                                                margin:
                                                    EdgeInsets.only(top: 8.h),
                                                child: InkWell(
                                                    onTap: () {
                                                      openSelectedDate(context);
                                                    },
                                                    child: Text.rich(
                                                        TextSpan(children: [
                                                      TextSpan(
                                                          text: '12月25号',
                                                          style: StylesUtils
                                                              .customTextStyle(
                                                                  fontSize:
                                                                      16.sp,
                                                                  color: ColorsUtils
                                                                      .color3333)),
                                                      TextSpan(
                                                          text: ' 周六',
                                                          style: StylesUtils
                                                              .customTextStyle(
                                                                  fontSize:
                                                                      13.sp,
                                                                  color: ColorsUtils
                                                                      .color3333))
                                                    ]))),
                                              )
                                            ],
                                          )),
                                          Container(
                                            padding: EdgeInsets.symmetric(
                                                horizontal: 10.w),
                                            child: Center(
                                              child: Text(
                                                '1晚',
                                                style:
                                                    StylesUtils.customTextStyle(
                                                        fontSize: 13.sp,
                                                        color: ColorsUtils
                                                            .color3333),
                                              ),
                                            ),
                                          ),
                                          Expanded(
                                              child: Column(
                                            children: [
                                              Container(
                                                alignment: Alignment.centerLeft,
                                                child: Text(
                                                  '明天离店',
                                                  style: StylesUtils
                                                      .customTextStyle(
                                                          fontSize: 12.sp,
                                                          color: ColorsUtils
                                                              .color9999),
                                                ),
                                              ),
                                              Container(
                                                alignment: Alignment.centerLeft,
                                                margin:
                                                    EdgeInsets.only(top: 8.h),
                                                child: InkWell(
                                                    onTap: () {
                                                      openSelectedDate(context);
                                                    },
                                                    child: Text.rich(
                                                        TextSpan(children: [
                                                      TextSpan(
                                                          text: '12月26号',
                                                          style: StylesUtils
                                                              .customTextStyle(
                                                                  fontSize:
                                                                      16.sp,
                                                                  color: ColorsUtils
                                                                      .color3333)),
                                                      TextSpan(
                                                          text: ' 周日',
                                                          style: StylesUtils
                                                              .customTextStyle(
                                                                  fontSize:
                                                                      13.sp,
                                                                  color: ColorsUtils
                                                                      .color3333))
                                                    ]))),
                                              )
                                            ],
                                          )),
                                        ],
                                      ),
                                    )),
                                Container(
                                  padding:
                                      EdgeInsets.only(top: 10.h, bottom: 20.h),
                                  alignment: Alignment.centerLeft,
                                  child: TextField(
                                    controller: controller.editingController,
                                    cursorWidth: 2.0,
                                    cursorRadius: const Radius.circular(2),
                                    cursorColor:
                                        ColorsUtils.parseColorFromHexString(
                                            ColorsUtils.color3333),
                                    style: StylesUtils.customTextStyle(
                                        fontSize: 16.sp,
                                        color: ColorsUtils.color3333),
                                    decoration: InputDecoration(
                                      prefixIcon: Container(
                                        alignment: Alignment.centerLeft,
                                        child: Text('试试搜：',
                                            style: StylesUtils.customTextStyle(
                                                color: ColorsUtils.color3333,
                                                fontSize: 16.sp)),
                                      ),
                                      prefixIconConstraints:
                                          BoxConstraints.expand(
                                              width: 70.w, height: 30.h),
                                      border: InputBorder.none,
                                      focusedBorder: InputBorder.none,
                                      hintText: '酒店/地名',
                                      contentPadding:
                                          EdgeInsets.symmetric(vertical: 12.h),
                                      isCollapsed: true,
                                      isDense: true,
                                      hintStyle: StylesUtils.customTextStyle(
                                          color: ColorsUtils.color3333,
                                          fontSize: 16.sp),
                                    ),
                                  ),
                                ),
                                Center(
                                  child: Container(
                                    alignment: Alignment.center,
                                    constraints: BoxConstraints.expand(
                                        width: 325.w, height: 45.h),
                                    decoration: BoxDecoration(
                                        borderRadius:
                                            BorderRadius.circular(8.w),
                                        gradient: LinearGradient(
                                            colors: [
                                              ColorsUtils.rgba(52, 120, 246, 1),
                                              ColorsUtils.rgba(2, 167, 240, 1)
                                            ],
                                            stops: const [
                                              0,
                                              0.99
                                            ],
                                            transform: GradientRotation(
                                                RadianUtils.angleToRadian(
                                                    90)))),
                                    child: TextButton(
                                        onPressed: () {
                                          Get.toNamed(RoutePath.hotelSearch);
                                        },
                                        child: Text(
                                          '查找酒店',
                                          style: StylesUtils.customTextStyle(
                                              fontSize: 16.sp),
                                        )),
                                  ),
                                )
                              ],
                            ),
                          )
                        ],
                      ),
                    ),
                  ),
                ),
                SliverPersistentHeader(
                  delegate: _SliverPersistentHeaderDelegate(
                      height: 50.h,
                      child: Container(
                        color: Colors.white,
                        child: Row(
                          children: controller.types
                              .asMap()
                              .map((index, row) => MapEntry(
                                    index,
                                    Expanded(
                                        child: InkWell(
                                      onTap: () {
                                        if (index !=
                                            controller.typeIndex.value) {
                                          controller.typeIndex.value = index;
                                        }
                                      },
                                      child: Column(
                                        children: [
                                          Expanded(
                                              child: Center(
                                                  child:
                                                      ToolsUtils.assetImageSvg(
                                                          row.icon,
                                                          width: 20.w,
                                                          height: 19.h))),
                                          Expanded(
                                              child: Center(
                                            child: Container(
                                              alignment: Alignment.center,
                                              constraints:
                                                  activeTypeBoxConstraints(
                                                      index),
                                              decoration:
                                                  activeTypeBoxDecoration(
                                                      index),
                                              child: Text(
                                                row.name,
                                                style: activeTypeStyle(index),
                                              ),
                                            ),
                                          ))
                                        ],
                                      ),
                                    )),
                                  ))
                              .values
                              .toList(),
                        ),
                      )),
                  pinned: true,
                ),
                SliverList(
                    delegate: SliverChildBuilderDelegate(
                  (_, index) {
                    var row = controller.pageList[index];
                    var width = ToolsUtils.calculateTextHeight(
                        context, row.area, FontWeight.normal, 12.sp, 250, 1);
                    return InkWell(
                      onTap: () {
                        Get.toNamed(RoutePath.hotelInfo,
                            arguments: {'hotel': row});
                      },
                      child: Container(
                          color: Colors.white,
                          padding: EdgeInsets.symmetric(
                              horizontal: 15.w, vertical: 10.h),
                          child: Column(
                            children: [
                              Stack(
                                children: [
                                  ClipRRect(
                                    borderRadius: BorderRadius.only(
                                        topLeft: Radius.circular(8.w),
                                        topRight: Radius.circular(8.w)),
                                    child: CachedNetworkImage(
                                      imageUrl: row.imgUrl,
                                      height: 200.h,
                                      width: double.infinity,
                                      fit: BoxFit.fill,
                                    ),
                                  ),
                                  Positioned(
                                      top: 0,
                                      left: 0,
                                      child: Container(
                                        alignment: Alignment.center,
                                        decoration: BoxDecoration(
                                            color:
                                                ColorsUtils.rgba(0, 0, 0, 0.6),
                                            borderRadius: BorderRadius.only(
                                                topLeft: Radius.circular(8.w),
                                                bottomRight:
                                                    Radius.circular(8.w))),
                                        constraints: BoxConstraints.expand(
                                            width: width + 20, height: 25.h),
                                        child: Text(
                                          row.area,
                                          style: StylesUtils.customTextStyle(
                                              fontSize: 12.sp),
                                        ),
                                      ))
                                ],
                              ),
                              Container(
                                padding: EdgeInsets.symmetric(
                                    vertical: 10.h, horizontal: 15.w),
                                alignment: Alignment.centerLeft,
                                child: Text(
                                  row.name,
                                  style: StylesUtils.customTextStyle(
                                      fontSize: 15.sp,
                                      color: ColorsUtils.color3333,
                                      fontWeight: FontWeight.w700),
                                ),
                              ),
                              Container(
                                padding: EdgeInsets.symmetric(horizontal: 15.w),
                                alignment: Alignment.centerLeft,
                                child: Row(
                                  mainAxisAlignment:
                                      MainAxisAlignment.spaceBetween,
                                  children: [
                                    Text(
                                      row.address,
                                      style: StylesUtils.customTextStyle(
                                          fontSize: 12.sp,
                                          color: ColorsUtils.color9999),
                                      maxLines: 1,
                                      overflow: TextOverflow.ellipsis,
                                    ),
                                    Text.rich(TextSpan(children: [
                                      TextSpan(
                                          text: '￥',
                                          style: StylesUtils.customTextStyle(
                                              fontSize: 13.sp,
                                              color: ColorsUtils.colorD900)),
                                      TextSpan(
                                          text: ' ${row.price} ',
                                          style: StylesUtils.customTextStyle(
                                              fontSize: 20.sp,
                                              fontWeight: FontWeight.w700,
                                              color: ColorsUtils.colorD900)),
                                      TextSpan(
                                          text: '起',
                                          style: StylesUtils.customTextStyle(
                                              fontSize: 12.sp,
                                              color: ColorsUtils.color9999))
                                    ]))
                                  ],
                                ),
                              )
                            ],
                          )),
                    );
                  },
                  childCount: controller.pageList.length,
                )),
                SliverToBoxAdapter(child: renderBottom())
              ],
            ),
          ),
        )
      ],
    );
  }

  Widget renderBottom() {
    if (controller.hasNext.isFalse) {
      return Container(
        padding: const EdgeInsets.symmetric(vertical: 15),
        alignment: Alignment.center,
        color: Colors.white,
        child: const Text(
          '已经到底',
          style: TextStyle(
            fontSize: 15,
            color: Color(0xFF333333),
          ),
        ),
      );
    }
    if (controller.isLoading.isTrue) {
      return Container(
        padding: const EdgeInsets.symmetric(vertical: 15),
        color: Colors.white,
        child: const Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              '努力加载中...',
              style: TextStyle(
                fontSize: 15,
                color: Color(0xFF333333),
              ),
            ),
            Padding(padding: EdgeInsets.only(left: 10)),
            SizedBox(
              width: 20,
              height: 20,
              child: CircularProgressIndicator(strokeWidth: 3),
            ),
          ],
        ),
      );
    }
    return Container(
      padding: const EdgeInsets.symmetric(vertical: 15),
      alignment: Alignment.center,
      color: Colors.white,
      child: const Text(
        '上拉加载更多',
        style: TextStyle(
          fontSize: 15,
          color: Color(0xFF333333),
        ),
      ),
    );
  }

  TextStyle activeTextStyle(int index) {
    if (controller.tabIndex.value == index) {
      return StylesUtils.customTextStyle(
          fontSize: 16.sp, fontWeight: FontWeight.bold);
    }
    return StylesUtils.customTextStyle(
        fontSize: 16.sp, color: ColorsUtils.color5555);
  }

  Color activeBackgroundColor(int index) {
    if (controller.tabIndex.value == index) {
      return ColorsUtils.parseColorFromHexString(ColorsUtils.color3478);
    }
    return Colors.transparent;
  }

  TextStyle activeTypeStyle(int index) {
    if (controller.typeIndex.value == index) {
      return StylesUtils.customTextStyle(fontSize: 13.sp);
    }
    return StylesUtils.customTextStyle(
        fontSize: 13.sp, color: ColorsUtils.color5555);
  }

  BoxDecoration? activeTypeBoxDecoration(int index) {
    if (controller.typeIndex.value == index) {
      return BoxDecoration(
          borderRadius: BorderRadius.circular(10.w),
          color: ColorsUtils.parseColorFromHexString(ColorsUtils.color3478));
    }
    return null;
  }

  BoxConstraints? activeTypeBoxConstraints(int index) {
    if (controller.typeIndex.value == index) {
      return BoxConstraints.expand(width: 60.w, height: 20.h);
    }
    return null;
  }

  Future<void> openSelectedDate(BuildContext context) async {
    List<DateTime?>? times = await ToolsUtils.showCalendarDatePickerDialog(
      context: context,
      config: CalendarDatePicker2WithActionButtonsConfig(
          firstDayOfWeek: 0,
          calendarType: CalendarDatePicker2Type.range,
          firstDate: DateTime.now(),
          calendarViewMode: DatePickerMode.day,
          weekdayLabels: [
            '周日',
            '周一',
            '周二',
            '周三',
            '周四',
            '周五',
            '周六',
          ],
          weekdayLabelTextStyle: StylesUtils.customTextStyle(
              fontSize: 13.sp, color: ColorsUtils.color0000),
          dayTextStyle: StylesUtils.customTextStyle(
              fontSize: 13.sp, color: ColorsUtils.color3333),
          todayTextStyle: StylesUtils.customTextStyle(
              fontSize: 13.sp, color: ColorsUtils.colorD900)),
      dialogSize: const Size(325, 420),
      dialogBackgroundColor: Colors.white,
    );
    Get.log('times = $times');
  }
}

class _SliverPersistentHeaderDelegate extends SliverPersistentHeaderDelegate {
  final double height;
  final Widget child;

  _SliverPersistentHeaderDelegate({required this.height, required this.child});

  @override
  Widget build(
      BuildContext context, double shrinkOffset, bool overlapsContent) {
    return child;
  }

  @override
  double get maxExtent => minExtent;

  @override
  double get minExtent => height;

  @override
  bool shouldRebuild(covariant SliverPersistentHeaderDelegate oldDelegate) {
    return this != oldDelegate;
  }
}
